<?php
	/* Pre-drop helper that deletes all attachments from WP Media Library when deleting a Pod record.
	   Specify 'File Upload' field names in $pod_file_fields, the default field is 'file'. */
	
	//list all the fields here that have attachments that you want to delete from WP Media Library when a Pod record is deleted.
	//the default field name is 'file'
	$pod_file_fields = array('file','image','logo');
	//accumulated array of all attachment ids of Pod's fields
	$attachment_ids = array();
	
	//set up pod obj
	$pod_name = $params->datatype;
	$pod_id = $params->tbl_row_id;
	$pod = new Pod($pod_name, $pod_id);
	
	//loop through all Pod's fields and accumulate all attachment ids from those fields
	foreach($pod_file_fields as $file_field){
		$field_attachments = $pod->get_field("$file_field.ID");
		
		//check if $field_attachments is array or string, put all attachment IDs into $attachment_ids
		if(is_array($field_attachments)){
			foreach($field_attachments as $att){
				$attachment_ids[] = $att;
			}
		}
		elseif(is_string($field_attachments)){
			$attachment_ids[] = $field_attachments;
		}
		else{}
	}
	
	//loop through all attachment ids and delete them
	foreach($attachment_ids as $att){
		wp_delete_attachment($att);
	}
?>